package me.leiusual.sharing.ui.shop

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations.switchMap
import androidx.lifecycle.ViewModel
import me.leiusual.sharing.api.model.WithdrawCreate
import me.leiusual.sharing.repository.WithdrawRepository
import me.leiusual.sharing.repository.model.Data
import me.leiusual.sharing.util.extension.toLiveData
import javax.inject.Inject

/**
 * author: leiusual
 * create on: 2019-08-01
 * description:
 */
class ShopWithdrawEditViewModel @Inject constructor(
    private val withdrawRepository: WithdrawRepository
) : ViewModel() {

  // 可提现账户

  private val _withdrawAccount = MutableLiveData<Unit>()
  val withdrawAccount: LiveData<Data<Map<String, String>>> = switchMap(_withdrawAccount) {
    withdrawRepository.withdrawAccount().toLiveData()
  }

  fun withdrawAccount() {
    _withdrawAccount.value = Unit
  }

  // 选中的账户

  private val _withdrawAccountSelected = MutableLiveData<Map<String, String>>()
  val withdrawAccountSelected: LiveData<Map<String, String>> = _withdrawAccountSelected
  fun withdrawAccountSelected(map: Map<String, String>) {
    _withdrawAccountSelected.value = map
  }

  // 创建

  private val _withdrawCreate = MutableLiveData<WithdrawCreate.Request>()
  val withdrawCreate: LiveData<Data<Unit>> = switchMap(_withdrawCreate) {
    withdrawRepository.withdrawCreate(it).toLiveData()
  }

  fun withdrawCreate(request: WithdrawCreate.Request) {
    _withdrawCreate.value = request
  }
}